//
//  OJProject.m
//  openJira
//
//  Created by Vincent Demay on 02/05/10.
//  Copyright 2010 Goojet. All rights reserved.
//

#import "OJProject.h"


@implementation OJProject

@synthesize name, key, lid;

- (void) dealloc
{
	[name release];
	[key release];
	[super dealloc];
}


@end

/////////////////////// OJPROJECTFILTER ////////////////////////

@implementation OJProjectList
@synthesize projects, delegate;

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}


- (void) getProjects{
	[[OJConnector getDefault] getProjects:self];
}


////////////////////////// MANAGE RESPONSES ///////////////////
- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response {
	id fromResponse = [response  object];
	[projects release];
	projects = [[NSMutableArray alloc] init];
	
	for (int i=0; i<[fromResponse count]; i++) {
		OJProject *project = [[OJProject alloc] init];
		project.name = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"name"];
		project.key = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"key"];
		
		project.lid = [[((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"id"] intValue];
		[projects addObject:project];
		[project release];
	}
	
	[delegate object:self isReady:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response {
	[delegate object:self isReady:YES];
}

@end
